package com.dingwen.treasure.business.controller;

import com.dingwen.treasure.base.controller.BaseViewController;
import com.dingwen.treasure.base.enums.ActivityStatusEnum;
import com.dingwen.treasure.base.util.EnumUtil;
import com.dingwen.treasure.base.pojo.vo.Result;
import com.dingwen.treasure.business.model.dto.EnumConvertDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;


/**
 * 　EnumConvertController: 枚举序列化和反序列化案例 </br>
 * <pre>
 *      1. 请求参数不试用
 * </pre>
 * <p>
 * 　@author dingwen
 * 　@date 2022/6/29
 */
@Api(tags = "枚举序列化和反序列化案例")
@RestController
@Slf4j
@RequestMapping("enum/convert")
public class EnumConvertController implements BaseViewController {

    @ApiOperation(value = "枚举序列化和反序列化DTO", response = Result.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "enumConvertDto", value = "dto", paramType = "body")
    })
    @PostMapping("dto")
    public Result<EnumConvertDto> enumConvertForDTO(@RequestBody EnumConvertDto enumConvertDto) {
        return success(enumConvertDto);
    }

    @ApiOperation(value = "枚举序列化和反序列化 enum", response = Result.class)
    @ApiImplicitParam(name = "state", value = "枚举", paramType = "query")
    @GetMapping("enum")
    public Result<ActivityStatusEnum> enumConvertForEnum(@RequestParam(value = "state") Integer state) {
        return success(EnumUtil.getEnumByCode(ActivityStatusEnum.class, state));
    }
}
